package com.tanger.common.jpa;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 查询参数构造器
 * @Author Hchenbin
 * @Date 2024-01-09 09:46
 * @Version 1.0
 */
@Data
@ApiModel(value = "查询参数")
public class QueryParams {

    @ApiModelProperty(value = "排序条件")
    private List<Order> sort;

    @ApiModelProperty(value = "查询属性")
    private List<MatcherReq> fields;

    @Data
    @Accessors(chain = true)
    public static class MatcherReq {
        @ApiModelProperty(value = "字段名(模糊查询多个字段时','号分隔)", required = true)
        private String name;
        @ApiModelProperty(value = "类型:LIKE:模糊查询 EQUAL:精确查询 BETWEEN:范围查询 " +
                                      "GREAT_EQUAL:大于等于 LESS_EQUAL:小于等于 " +
                                      "NOT_EQUAL:不等于 IN:多参数内等常用表达式",
                allowableValues = "EQUAL", required = true)
        private String type;
        @ApiModelProperty(value = "字段值，范围查询时参数形式{\"start\":1,\"end\":2}", required = true)
        private Object value;
    }

    public static class Order {
        @ApiModelProperty(value = "描述(ASC:正序 DESC:倒序)")
        private String direction;
        @ApiModelProperty(value = "排序字段名")
        private String property;

        public String getDirection() {
            return direction;
        }

        public Order setDirection(String direction) {
            this.direction = direction;
            return this;
        }

        public String getProperty() {
            return property;
        }

        public Order setProperty(String property) {
            this.property = property;
            return this;
        }
    }

    public List<Order> getSort() {
        return sort;
    }

    public QueryParams setSort(List<Order> sort) {
        this.sort = sort;
        return this;
    }
}
